package org.example.com.controller;


import org.apache.ibatis.annotations.Param;
import org.example.com.pojo.Result;
import org.example.com.service.FavoriteService;
import org.example.com.pojo.vo.FavoriteVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/auth/user/favorites")
public class FavoriteController {

    @Autowired
    FavoriteService favoriteService;

    /**
     * 查询收藏的房源列表
     * @return
     */
    @GetMapping
    public Result getList() {
        List<FavoriteVO> favorites = favoriteService.getList();
        return Result.success(favorites);
    }

    /**
     * 收藏房源
     * @param houseId
     * @return
     */
    @PostMapping("")
    public Result addFavorite(@RequestBody int houseId) {
        System.out.println(houseId);
        favoriteService.addFavorite(houseId);
        return Result.success();
    }

    /**
     * 取消收藏房源
     * @param houseId
     * @return
     */
    @DeleteMapping("/{houseId}")
    public Result deleteFavorite(@PathVariable int houseId) {
        favoriteService.deleteFavorite(houseId);
        return Result.success();
    }
}
